﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace Qianke.Core.Common.Http
{
    public enum DataType
    {
        字符串,

        文件,

        缓冲区,
    }

    public class HttpConfig
    {
        /// <summary>
        /// 是否通过压缩传输
        /// </summary>
        public bool IsZipSend { set; get; } = false;

        /// <summary>
        /// 请求URL必须填写
        /// </summary>
        public string URL { set; get; }

        /// <summary>
        /// 请求方式默认为GET方式,当为POST方式时必须设置Postdata的值
        /// </summary>
        public string Method { set; get; } = "GET";

        /// <summary>
        /// 默认请求超时时间
        /// </summary>
        public int Timeout { set; get; } = 100000;
        /// <summary>
        /// 默认写入Post数据超时间
        /// </summary>
        public int ReadWriteTimeout { set; get; } = 100000;


        /// <summary>
        ///  获取或设置一个值，该值指示是否与 Internet 资源建立持久性连接默认为true。
        /// </summary>
        public Boolean KeepAlive { set; get; } = true;


        /// <summary>
        /// 请求标头值 默认为text/html, application/xhtml+xml, */*
        /// </summary>
        public string Accept { set; get; } = "text/html, application/xhtml+xml, */*";


        /// <summary>
        /// 请求返回类型默认 text/html
        /// </summary>
        public string ContentType { set; get; } = "text/html";

        /// <summary>
        /// 客户端访问信息默认Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
        /// </summary>
        public string UserAgent { set; get; } = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";


        /// <summary>
        /// 返回数据编码默认为NUll,可以自动识别,一般为utf-8,gbk,gb2312
        /// </summary>
        public Encoding Encoding { set; get; } = null;

        /// <summary>
        /// Post的数据类型
        /// </summary>
        public DataType PostDataType { set; get; } = DataType.字符串;


        /// <summary>
        /// Post请求时要发送的字符串Post数据
        /// </summary>
        public string Postdata { set; get; }

        /// <summary>
        /// Post请求时要发送的Byte类型的Post数据
        /// </summary>
        public byte[] PostdataByte { set; get; }


        /// <summary>
        /// 设置代理对象，不想使用IE默认配置就设置为Null，而且不要设置ProxyIp
        /// </summary>
        public WebProxy WebProxy { set; get; }

        /// <summary>
        /// Cookie对象集合
        /// </summary>
        public CookieCollection CookieCollection { set; get; }

        /// <summary>
        /// 请求时的Cookie
        /// </summary>
        public string Cookie { set; get; }

        /// <summary>
        /// 来源地址，上次访问地址
        /// </summary>
        public string Referer { set; get; }


        /// <summary>
        /// 证书绝对路径
        /// </summary>
        public string CerPath { set; get; }

        /// <summary>
        /// 是否设置为全文小写，默认为不转化
        /// </summary>
        public Boolean IsToLower { set; get; } = false;

        /// <summary>
        /// 支持跳转页面，查询结果将是跳转后的页面，默认是不跳转
        /// </summary>
        public Boolean Allowautoredirect { set; get; } = false;

        /// <summary>
        /// 最大连接数
        /// </summary>
        public int Connectionlimit { set; get; } = 1024;


        /// <summary>
        /// 代理Proxy 服务器用户名
        /// </summary>
        public string ProxyUserName { set; get; }


        /// <summary>
        /// 代理 服务器密码
        /// </summary>
        public string ProxyPwd { set; get; }


        /// <summary>
        /// 代理 服务IP ,如果要使用IE代理就设置为ieproxy
        /// </summary>
        public string ProxyIp { set; get; }


        /// <summary>
        /// 设置返回类型String和Byte
        /// </summary>
        public DataType ResultType { set; get; } = DataType.字符串;

        /// <summary>
        /// header对象
        /// </summary>
        public WebHeaderCollection Header { set; get; } = new WebHeaderCollection();


        /// <summary>
        //     获取或设置用于请求的 HTTP 版本。返回结果:用于请求的 HTTP 版本。默认为 System.Net.HttpVersion.Version11。
        /// </summary>
        public Version ProtocolVersion { set; get; }


        /// <summary>
        ///  获取或设置一个 System.Boolean 值，该值确定是否使用 100-Continue 行为。如果 POST 请求需要 100-Continue 响应，则为 true；否则为 false。默认值为 true。
        /// </summary>
        public Boolean Expect100Continue { set; get; } = true;

        /// <summary>
        /// 设置509证书集合
        /// </summary>
        public X509CertificateCollection ClentCertificates { set; get; }


        /// <summary>
        /// 设置或获取Post参数编码,默认的为Default编码
        /// </summary>
        public Encoding PostEncoding { set; get; }

        /// <summary>
        /// Cookie返回类型,默认的是只返回字符串类型
        /// </summary>
        public DataType ResultCookieType { set; get; } = DataType.字符串;

        /// <summary>
        /// 获取或设置请求的身份验证信息。
        /// </summary>
        public ICredentials ICredentials { set; get; } = CredentialCache.DefaultCredentials;

    }
}
